﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using VK.Casemeet.Members;
using VK.Casemeet.Groups;
using System.Web.SessionState;

namespace VK.Casemeet.Web.PageHandler
{
    /// <summary>
    /// 团购报名
    /// </summary>
    public class GroupSigup : IHttpHandler, IRequiresSessionState
    {
        /// <summary>
        /// 1.判定用户是否登陆.
        /// 2.用户是否参加过团购.
        /// 3.可以进行团购.
        /// </summary>
        /// <param name="context"></param>
        
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            if (MemberBLL.IsSessionMember())//证明用户已经登录
            {
                if (context.Request["groupid"] != null)
                {
                    int groupid = Convert.ToInt32(context.Request["groupid"]);//团购报名ID号
                    if (!GroupMembersBLL.IsSignupGroup(groupid, MemberBLL.GetSessionMember().MemberID))
                    {
                        GroupMembers groupmember = new GroupMembers { groupid = groupid, memberid = MemberBLL.GetSessionMember().MemberID };
                        int result = GroupMembersBLL.AddGroupsUser(groupmember);
                        context.Response.Write("OK");
                    }
                    else
                    {
                        context.Response.Write(Enum_GroupIsSignup.已参加过团购.ToString("D"));//输出1为已经参加过报名.
                    }
                }
            }
           
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}